package com.example.feature.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.feature.demo.dto.UserQueryDto;
import com.example.feature.demo.entity.Users;
import com.example.feature.demo.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhou
 * @since 2021-05-19
 */
@RestController
@RequestMapping("/common/users")
public class UsersController {

    @Autowired
    private IUsersService usersService;

    @GetMapping
    public List get() {
        QueryWrapper<Users> wrapper = new QueryWrapper<>();
        wrapper.lambda().likeRight(Users::getUsername, "zhou");
        List<Users> list = usersService.list(wrapper);
        return list;
    }

    @PostMapping("/page")
    public IPage<Users> page(@RequestBody UserQueryDto pageDTO) {
        return usersService.selectPageVo(pageDTO);
    }

    /**
     * kafka事物测试
     *
     * @param users
     */
    @PostMapping("/add")
    public void add(@RequestBody Users users) {
        usersService.insertUser(users);
    }

}
